#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
int Judge(int* num, int n)
{
	int count = 1;
	
		if (num[1] != num[0])
		{
			count++;
		}
		if (num[2] != num[1] && num[2] != num[0])
		{
			count++;
		}
		if (num[3] != num[1] && num[3] != num[0] && num[3] != num[2])
		{
			count++;
		}
		if (count == n)
			return 1;
		return 0;
	
}
int main()
{
	int num[4] = { 0 };
	int y = 0;
	int n = 0;
	scanf("%d%d", &y, &n);
	int i = y;
	for (i = y;; i++)
	{
		int m = i;
		for (int j = 0; j < 4; j++)
		{
			num[j] = m % 10;
			m /= 10;
		}
		if (Judge(num, n) == 1)
		{
			break;
		}
	}
	printf("%d %d", i - y, i);
	
	return 0;
}